<?php
class v1_setting{
    function banner(){
	    $config=$this->yum->model('config');
	    if($this->yum->post('save',true)){
	    	$setting=array();$data['message']=array('result'=>false,'msg'=>array());
	    	$directory=$this->yum->vars('app','slide');
    		$httpupload=$this->yum->library('httpupload',array('max'=>1024*1024,'limit'=>array('jpg','png','gif'),'directory'=>$directory));
			$httpupload->ini(array('level'=>true));
			for($i=1;$i<=8;$i++){
				$result=$httpupload->saveAs(str_shuffle('ABCDEF0123456789'),'slide'.$i);
				if($result!==false){
					$setting[]=array('slide',$i,str_replace($directory,'',$result));
				}
			}
			if(empty($setting)){
				$data['message']['msg'][]='上传文件错误,仅接受jpg、png、gif大小为1M文件.';
			}else{
				$affected=$config->RConfig(array('field'=>array('label','name','value'),'value'=>$setting));
	    		if($affected==0){
					$data['message']['msg'][]='错误的上传参数.';
	    		}else{
	    			$data['message']['result']=true;
					$data['message']['msg'][]='Banner修改成功.';
	    		}
			}
	    }
	    $data['session']=array($this->yum->vars('lib','session','name'),$_COOKIE[$this->yum->vars('lib','session','name')]);
	    $this->yum->set($data);
	    $this->yum->view('banner.php');
    }
    function finance(){
    	$config=$this->yum->model('config');
    	if($this->yum->post('save',true)){
    		$data['message']=array('result'=>false,'msg'=>array());
    		$setting=array();
    		$setting[]=array('finance','auto',$this->yum->post('auto',true));
    		$setting[]=array('finance','min',$this->yum->post('min',true));
    		$setting[]=array('finance','cess',$this->yum->post('cess',true));
    		$setting[]=array('finance','outlay',$this->yum->post('outlay',true));
    		$affected=$config->RConfig(array('field'=>array('label','name','value'),'value'=>$setting));
    		if($affected==0){
				$data['message']['msg'][]='错误的配置参数.';
    		}else{
    			$data['message']['result']=true;
				$data['message']['msg'][]='财务配置修改成功.';
    		}
    	}
    	$finance=$config->GConfig(array('where'=>array('label ='=>'finance')));
    	foreach($finance as $key =>$value){
    		$data[$value['name']]=$value['value'];
    	}
    	$this->yum->set($data);
		$this->yum->view('finance.php');
    }
    function email(){
    	$config=$this->yum->model('config');
    	$data['code']=$this->yum->get('code',true);
    	if($this->yum->post('save',true)){
    		$data['message']=array('result'=>false,'msg'=>array());
    		$data['code']=$this->yum->post('code',true);
    		$value['subject']=$this->yum->post('subject',true);
    		$value['content']=htmlspecialchars($this->yum->post('content'));
    		if(empty($value['subject'])){
    			$data['message']['msg'][]='邮件标题不可为空.';
    		}else{
    			$affected=$config->UConfig(array('where'=>array('label='=>'mail','name='=>$data['code']),'set'=>array('value ='=>serialize($value))));
    			if($affected==0){
    				$data['message']['msg'][]='请误提交未修改过数据.';
    			}else{
    				$data['message']['result']=true;
					$data['message']['msg'][]='模板修改成功.';
    			}
    		}
    	}
    	$email=$config->GConfig(array('where'=>array('label='=>'mail')));
    	foreach($email as $key=>$value){
    		$value['value']=preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'",$value['value']);
    		$value['value']=unserialize($value['value']);
    		$data['email'][$key]=$value;
    	}
    	$this->yum->set($data);
		$this->yum->view('email.php');
    }
    function advertiser(){
     	$config=$this->yum->model('config');
    	if($this->yum->post('save',true)){
    		$data['message']=array('result'=>false,'msg'=>array());
    		$setting=array();
    		$setting[]=array('advertiser','outlet',$this->yum->post('outlet',true));
    		$setting[]=array('advertiser','customize',$this->yum->post('customize',true));
    		$setting[]=array('advertiser','init',$this->yum->post('init',true));
    		$setting[]=array('advertiser','server',$this->yum->post('server',true));
    		$setting[]=array('advertiser','material',$this->yum->post('material',true));
    		$affected=$config->RConfig(array('field'=>array('label','name','value'),'value'=>$setting));
    		if($affected==0){
				$data['message']['msg'][]='错误的配置参数.';
    		}else{
    			$data['message']['result']=true;
				$data['message']['msg'][]='广告配置修改成功.';
    		}
    	}
    	$adsystem=$config->GConfig(array('where'=>array('label ='=>'advertiser')));
    	foreach($adsystem as $key =>$value){
    		$data[$value['name']]=$value['value'];
    	}
    	$this->yum->set($data);
    	$this->yum->view('advertiser.php');
    }
    function protocol(){
    	$config=$this->yum->model('config');
    	if($this->yum->post('save',true)){
    		$data['message']=array('result'=>false,'msg'=>array());
    		$content=$this->yum->post('content',true);
    		$affected=$config->UConfig(array('where'=>array('label='=>'union','name='=>'protocol'),'set'=>array('value ='=>$content)));
    		if($affected==0){
    			$data['message']['msg'][]='请误提交未修改过数据.';
    		}else{
    			$data['message']['result']=true;
				$data['message']['msg'][]='协议修改成功.';
    		}
    	}
    	$data['protocol']=reset($config->GConfig(array('where'=>array('label='=>'union','name='=>'protocol'))));
    	$this->yum->set($data);
    	$this->yum->view('protocol.php');
    }
    function foot(){
    	$config=$this->yum->model('config');
    	if($this->yum->post('save',true)){
    		$data['message']=array('result'=>false,'msg'=>array());
    		$content=$this->yum->post('content',true);
    		$affected=$config->UConfig(array('where'=>array('label='=>'union','name='=>'foot'),'set'=>array('value ='=>$content)));
    		if($affected==0){
    			$data['message']['msg'][]='请误提交未修改过数据.';
    		}else{
    			$data['message']['result']=true;
				$data['message']['msg'][]='页脚修改成功.';
    		}
    	}
    	$data['foot']=reset($config->GConfig(array('where'=>array('label='=>'union','name='=>'foot'))));
    	$this->yum->set($data);
    	$this->yum->view('foot.php');
    }
}
?>